<template>
    <div class="manage">
        <div class="manage-header">
            <!-- 搜索表单 -->
            <el-form :inline="true" :model="search">
                <el-form-item>
                    <el-button type="primary" size="mini" @click="getList">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="common-tabel">
            <el-table stripe height="100%" border :data="tableData" style="width: 100%" v-loading="loading" size="mini">
                <el-table-column prop="pet_id" label="宠物Id" align="center">
                </el-table-column>
                <el-table-column prop="username" label="领养者用户名" align="center">
                </el-table-column>
                <el-table-column prop="nickname" label="领养者昵称" align="center">
                </el-table-column>
                <el-table-column prop="name" label="领养者姓名" align="center">
                </el-table-column>
                <el-table-column prop="mobile" label="领养者电话" align="center">
                </el-table-column>
                <el-table-column prop="gender" label="领养者性别" align="center">
                </el-table-column>
                <el-table-column prop="profession" label="领养者职业" align="center">
                </el-table-column>
                <el-table-column prop="salary" label="领养者收入" align="center">
                </el-table-column>
                <el-table-column prop="reason" label="领养理由" align="center">
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center">
                    <template slot-scope="scope">
                        {{ statuMap[scope.row.status] }}
                    </template>
                </el-table-column>
                <el-table-column prop="created" label="发布时间" align="center">
                </el-table-column>
                <el-table-column prop="action" label="审核" align="center" width="150px">
                    <template slot-scope="scope" v-if="scope.row.status == 2 && scope.row.r_user_id == 0">
                        <el-button type="primary" size="mini" @click="handle(scope.row, 1)">通过</el-button>
                        <el-button type="danger" size="mini" @click="handle(scope.row, 0)">拒绝</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="action" label="操作" align="center" width="100px">
                    <template slot-scope="scope">
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
import { recordList, recordDelete, recordEdit } from '@/api/record.js';
export default {
    data() {
        return {
            tableData: [],
            search: {
                content: '',
            },
            loading: false,
            statuMap: {
                0: '审核未通过',
                1: '审核通过',
                2: '审核中',
                3: '已取消申请'
            }
        }
    },
    methods: {
        handle(row, num) {
            recordEdit({ id: row.id, status: num }).then(() => {
                this.getList()
            })
        },
        handleDelete(row) {
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                recordDelete({ id: row.id }).then(() => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getList()
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 获取列表
        getList() {
            this.loading = true;
            recordList({ content: this.search.content }).then((data) => {
                this.tableData = data.result
                this.loading = false;
            })
        },
    },
    mounted() {
        this.getList()
    }
}
</script>
<style lang="less" scoped>
.manage {
    height: 100%;

    .manage-header {
        display: flex;
        justify-content: end;
        align-items: center;
        margin-bottom: 10px;

        .el-form-item {
            margin-bottom: 0;
        }

        /deep/.el-form-item__content {
            line-height: 0;
        }
    }

    .common-tabel {
        position: relative;
        height: calc(100% - 62px);
    }
}
</style>